import request from '@/utils/request'
import type { ApiResult, BaseIds, PageSchema } from '@/api/api'
import type {
  Dept,
  DeptAddDTO,
  DeptModDTO,
  DeptQueryDTO,
} from '@/api/system/dept/type'
const BASE_URL = '/admin/api/v1/system/dept'
const API = {
  BASE_URL,
  PAGE_URL: BASE_URL + '/page',
  LIST_URL: BASE_URL + '/list',
  REMOVE_URL: BASE_URL + '/rm',
  TREE_URL: BASE_URL + '/tree',
}
// 添加部门信息
export const deptAdd = (data: DeptAddDTO) => {
  return request.post<any, ApiResult<unknown>>(API.BASE_URL, data)
}
// 修改部门信息
export const deptMod = (data: DeptModDTO) => {
  return request.put<any, ApiResult<unknown>>(API.BASE_URL, data)
}
// 删除部门信息
export const deptDel = (data: BaseIds) => {
  return request.post<any, ApiResult<unknown>>(API.REMOVE_URL, data)
}
// 查询部门信息
export const deptList = (data: DeptQueryDTO) => {
  return request.post<any, ApiResult<Dept[]>>(API.LIST_URL, data)
}
// 查询分页数据
export const deptQuery = (data: DeptQueryDTO) => {
  return request.post<any, ApiResult<PageSchema<Dept>>>(API.PAGE_URL, data)
}

export const deptTree = () => {
  return request.get<any, ApiResult<Dept[]>>(API.TREE_URL)
}
